﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Diagnostics;

namespace JasLib.Diagnostics
{
    public static class DebugUtilities
    {
        /// <summary>
        /// This version of Debug.Assert throws an exception in release builds to absolutely prevent further execution.
        /// </summary>
        public static void Assert(bool bCondition, string strMessage = null)
        {
            if (!bCondition)
            {
                Break();
                throw new AssertionException(strMessage);
            }
        }

        /// <summary>
        /// This version of Debugger.Break launches the debugger if not attached, rather than silently failing.
        /// </summary>
        [Conditional("DEBUG")]
        public static void Break()
        {
            if (Debugger.IsAttached)
                Debugger.Break();
            else
                Debugger.Launch();
        }
    }
}
